use rand::{distributions::Slice, Rng};

const LEGAL_CHARS: [char; 36] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
const PREFIX:&'static str = "AHOUKUSE-";
pub fn gen_client_id() -> String {
    let rng = rand::thread_rng();
    let chars_dis = Slice::new(LEGAL_CHARS.as_slice()).unwrap();
    let id:String = rng.sample_iter(&chars_dis).take(20 - PREFIX.len()).collect();
    let mut res = String::new();
    res.push_str(&PREFIX);
    res.push_str(&id);
    res
}

#[cfg(test)]
mod test {
    use crate::util::gen_client_id;


    #[test]
    fn test_gen_client_id() {
        for _ in 0..10 {
            let id = gen_client_id();
            println!("{} - {}", id, id.len())
        }
    }
}
